import * as types from "../types/editUserInfoTypes";

const initialState = {
  loading: false,
  error: undefined,
  success: false,
  uploadSuccess: false,
  nickname: "",
  headerSrc: "",
};

export default function editUserInfoReducer(state = initialState, action) {
  switch (action.type) {
    case types.EDITUSERINFO_LOADING:
      return {
        ...state,
        loading: true,
      };
    case types.EDITUSERINFO_DONE:
      return {
        ...state,
        loading: false,
        success: true,
      };
    case types.EDITUSERINFO_ERROR:
      return {
        ...state,
        loading: false,
        error: action.error,
      };
    case types.EDITUSERINFO_INIT:
      return {
        ...state,
        nickname: action.nickname,
        headerSrc: action.headerSrc,
      };
    case types.EDITUSERINFO_INPUT_NAME:
      return {
        ...state,
        nickname: action.nickname,
      };
    case types.EDITUSERINFO_UPLOAD_DONE:
      return {
        ...state,
        loading: false,
        uploadSuccess: true,
        headerSrc: action.headerSrc,
      };
    case types.EDITUSERINFO_UPLOAD_ERROR:
      return {
        ...state,
        loading: false,
        error: action.error,
      };
    case types.EDITUSERINFO_UNMOUNT:
      return {
        ...initialState,
      };
    default:
      return state;
  }
}
